package com.winning.zjjh.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.winning.zjjh.dao.UDDao;
import com.winning.zjjh.service.UDService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.lang.reflect.Field;
import java.util.Iterator;
import java.util.List;

/**
 * @Author: xkh@winning.com.cn
 * @Desc: TODO
 * @Date: 2019-03-18 13:23
 **/
@Service
@Transactional
public class UDServiceImpl implements UDService {

    @Autowired
    UDDao udDao;

    @Override
    public IPage selectChfs(Page page, String tablename, String date) {
        return udDao.selectChfs(page, tablename, date);
    }

    @Override
    public IPage selectCh42(Page page, String tablename, String date) {
        return udDao.selectCh42(page, tablename, date);
    }

    @Override
    public IPage selectYcja(Page page, String tablename, String date) {
        return udDao.selectYcja(page, tablename, date);
    }

    @Override
    public IPage selectEbjc(Page page, String tablename, String date) {
        return udDao.selectEbjc(page, tablename, date);
    }

    @Override
    public IPage selectEbja(Page page, String tablename, String date) {
        IPage iPage = udDao.selectEbja(page,tablename,date);
        return verification(iPage);
    }

    @Override
    public IPage selectGesf(Page page, String tablename, String date) {
        IPage iPage = udDao.selectGesf(page,tablename,date);
        return verification(iPage);
    }

    @Override
    public IPage selectGeyy(Page page, String tablename, String date) {
        IPage iPage = udDao.selectGeyy(page,tablename,date);
        return verification(iPage);
    }

    @Override
    public IPage selectJktj(Page page, String tablename, String date) {
        IPage iPage = udDao.selectJktj(page, tablename, date);
        return verification(iPage);
    }

    @Override
    public IPage selectRegCard(Page page, String tablename, String date) {
        IPage regCardIPage = udDao.selectRegCard(page, tablename, date);
        return regCardIPage;
    }

    @Override
    public IPage selectFirstVisit(Page page, String tablename, String date) {
        IPage firstVisitEntityIPage = udDao.selectFirstVisit(page, tablename, date);
        return firstVisitEntityIPage;
    }

    @Override
    public IPage selectPregnancyHistory(Page page, String tablename, String date) {
        IPage pregnancyHistoryEntityIPage = udDao.selectPregnancyHistory(page, tablename, date);
        return pregnancyHistoryEntityIPage;
    }

    @Override
    public IPage selectFurtherVisit(Page page, String tablename, String date) {
        IPage furtherVisitEntityIPage = udDao.selectFurtherVisit(page, tablename, date);
        return furtherVisitEntityIPage;
    }

    @Override
    public IPage selectChildbirth(Page page, String tablename, String date) {
        IPage shildbirthEntityIPage = udDao.selectChildbirth(page, tablename, date);
        return shildbirthEntityIPage;
    }

    @Override
    public IPage selectEbdjjk(Page page, String tablename, String date) {
        IPage iPage = udDao.selectEbdjjk(page, tablename, date);
        return iPage;
    }

    @Override
    public IPage selectXsrfs(Page page, String tablename, String date) {
        IPage iPage = udDao.selectXsrfs(page, tablename, date);
        return iPage;
    }

    @Override
    public int insertDate(String tablename, String date) {
        return udDao.insertDate(tablename, date);
    }


    private IPage verification(IPage iPage)  {
        List records = iPage.getRecords();
        Iterator iterator = records.iterator();
        while (iterator.hasNext()) {
            try{
                Object obj = iterator.next();
                Field rid = obj.getClass().getDeclaredField("RID");
                rid.setAccessible(true);
                Object value = rid.get(obj);
                if (String.valueOf(value).equals("7215EE9C7D9DC229D2921A40E899EC5F")) {
                    iterator.remove();
                }
            }catch (Exception e){
                continue;
            }
        }

        return iPage;
    }
}
